var id=location.search;
id=id.split('?')[1];
var attach="";
var answer=null;
var sec="";
var sub="";
if (islogin()) {
    $.post({
        url:'../../requests/teacher/select_detail_homework.php',
        data:{'id':id},
        async:false,
        success:function (data) {
            console.log(data);
            sec=data[0].section;
            sub=data[0].subsection;
            $('#h-title').text(data[0].title);
            $('#h-notice').text(data[0].notice);
            if (data[0].deadline!='0000-00-00 00:00:00'){
                $('#h-deadline').text(data[0].deadline);
            }
            else $('#h-deadline').text('无');

            if (data[0].section !="0") {
                $('#sec-num').text(data[0].section+".");
            }
            else $('#sec-num').text('无');

            if (data[0].subsection != "0") {
                $('#sub-num').text(data[0].subsection+".");
            }
            else $('#sub-num').text('无');

            if (data[0].attach == "") {
                $('#d-attach').text('无');
            }
            else attach="../../"+data[0].attach;

            if (data[0].answer==null) {
                $('#d-answer').text('无');
            }
            else answer="../../"+data[0].answer;
        }
    });

    if (sec != 0) {
        $.post({
            url:'../../requests/teacher/select_homework_sec.php',
            data:{'sec':sec,'id':id,'sub':sub},
            success:function (data) {
                $('#sec-name').text(data.sec);
                if (data.sub != "0") {
                    $('#sub-name').text(data.sub);
                }
            }
        });
    }

    if (attach != "") {
        $('#d-attach').attr('href',attach);
    }
    if (answer != "") {
        $('#d-answer').attr('href',answer);
    }

    $('#btn_del').click(function () {
        $$.confirm('删除作业将删除作业有关的所有文件','确认删除？',function () {
            $.post({
                url:'../../requests/teacher/delete_homework.php',
                data:{'id':id},
                success:function (data) {
                    if (data == '1') {
                        $$.alert('删除成功',function () {
                            history.go(-1);
                        })
                    }
                }
            });
        });
    });
    $('#btn_show').click(function () {
        window.location.href = "submit_detail.html?"+id;
    });
}
else window.location.href='../../index.html';